<?php
    require_once "config.php";
    require_once "weixin_info.php";
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        $date = array(
            'bank_id'      => $_POST['bank_id'],
            'money'      => $_POST['money'],
        );
        $sql = $mysql->query("select * from dyspw_mem_bank where  id = {$date['bank_id']} ");
        $bank = $sql->fetch_all(MYSQLI_ASSOC);
        if(empty($bank)){
            $result['status'] = 'n';
            $result['info'] = '未查询到该银行卡信息';
            exit(json_encode($result));
        }
        if($date['money'] > $_SESSION['Member_info'][0]['balance']){
            $result['status'] = 'n';
            $result['info'] = '余额不足，请重新输入';
            exit(json_encode($result));
        }
        if($date['money']%100 != 0){
            $result['status'] = 'n';
            $result['info'] = '提现金额必须为100的倍数，请重新输入';
            exit(json_encode($result));
        }
        $time = time();
        $cash_add = $mysql->query("INSERT INTO dyspw_shop_detailed (u_id, u_name, u_avatar, type, cash_money, bank_id, case_state, case_time) VALUES ({$_SESSION['Member_info'][0]['id']}, '{$_SESSION['Member_info'][0]['username']}','{$_SESSION['Member_info'][0]['avatar']}',2, {$date['money']}, {$date['bank_id']}, 0, {$time})");
        if($cash_add){
            $mysql->query("UPDATE dyspw_member SET balance = balance-{$date['money']} WHERE id={$_SESSION['Member_info'][0]['id']}");
            $result['status'] = 'y';
            $result['info'] = '提现申请成功，请等待审核';
            exit(json_encode($result));
        }else{
            $result['status'] = 'n';
            $result['info'] = '提现申请提交失败，请重新提交';
            exit(json_encode($result));
        }
    }
 ?>
